import time

from Model.sqlConfig import getSession
from fastapi import Depends
from Model.ModelOne import FaskApi_cli

db=getSession()

class VetionBassiness:
    @classmethod
    def getList(self):
        return db.query(FaskApi_cli).all()
    @classmethod
    def add(self,name,vertion):
        db.begin()
        try:
            mydict = FaskApi_cli(name=name,vertion=vertion)
            db.add(mydict)
            db.commit()
            return True
        except:
            db.rollback()
            return False
    @classmethod
    def delete(self,id):
        try:
            db.delete(db.query(FaskApi_cli).get(id))
            db.commit()
            return True
        except:
            return False
    @classmethod
    def update(self,data:FaskApi_cli):
        try:
            mydict:FaskApi_cli = db.query(FaskApi_cli).get(data.id)
            if mydict!=None and mydict!='':
                mydict.name=data.name if mydict.name!='' else None
                mydict.vertion =data.vertion if mydict.vertion != '' else None
                db.commit()
                return True
            else:
                return False
        except:
            return False